Answer:

No.

Car Purchase as a Program

All you need is money OR credit. Just one would do. Of course, if you had lots of money and plenty of credit you could certainly buy the car.

Sometimes a program has to test if just one of the conditions has been met. Here is how that is done with the car purchase problem:

// Sports Car Purchase
//
// You need $25000 in cash or credit
//
import java.util.Scanner;

class HotWheels
{
  public static void main (String[] args) 
  { 
    Scanner scan = new Scanner( System.in ); 
    int cash, credit ; 

    // get the cash
    System.out.print("How much cash? ");
    cash = scan.nextInt() ; 

    // get the credit line
    System.out.print("How much credit? ");
    credit = scan.nextInt() ; 

    // check that at least one qualification is met
    if ( cash >= 25000  ||  credit >= 25000 )
      System.out.println("Enough to buy this car!" );
    else
      System.out.println("What about a Yugo?" );

  }
}

The symbol || (vertical-bar vertical-bar) means "OR." On your keyboard, vertical-bar is the top character on the key above the "enter" key. The OR operator evaluates to true when either qualification is met or when both are met. The if statement asks a question with two parts:

if cash >= 25000 || credit >= 25000 
   ----------         ----------
   cash part          credit part

If either part is true, or both parts are true, then the entire boolean expression is true.

QUESTION 17:

Say that you enter 56000 for cash and 0 for credit. What answer (true or false) does each part give you?

               
cash  >= 25000  

credit >= 25000  

What does the entire boolean expression give you?

               
cash  >= 25000 || credit >= 25000